﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using GCELibrary.Current;

namespace ZF.WS.news
{
    public partial class NewMaster : System.Web.UI.MasterPage
    {
        public int VisRnd { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {
            VisRnd=((new Random()).Next(1,4));
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                var hotList = dc.SP_Merchandise.Where(p => !p.IsDel).OrderBy(p => p.IsPromotions).OrderByDescending(p => p.Hits).Take(4).ToList().Select(p => new
                {
                    Merc = p,
                }).ToList();
                this.lvHot.DataSource = hotList;
                this.lvHot.DataBind();


                this.lvNews.DataSource = dc.I_News.OrderByDescending(p => p.NewsId).Take(10).ToList();
                this.lvNews.DataBind();
            }

            using (var dc = SiteInfo.CreateDBDataContext())
            {

                List<object> list = null;
                var cacheKey = "news_index_JPLP";
                var obj = HttpCache.GetCache(cacheKey);
                if (obj != null)
                {
                    list = obj as List<object>;
                }
                else
                {
                    list = dc.H_Estate.Where(p => p.IsVerify)
                     .OrderByDescending(p => p.EstateId).Take(18).ToList().Select(p => (object)p).ToList();
                    SiteInfo.Instance.SetPageCache(cacheKey, list);
                }
                this.lvJPLP.DataSource = list;
                this.lvJPLP.DataBind();
            }

        }
    }
}
